import React from "react";
import { useParams,useLocation,useNavigate} from "react-router";
import { useEffect } from "react";
const Detail=()=>{
    const navigate=useNavigate()
    let id = null;
    
    const paramsObj = useParams();
    // console.log(paramsObj)
    if (paramsObj?.id) {
        id = paramsObj.id
    } else {
        let searchObj = new URLSearchParams(useLocation().search)
        if (searchObj.get('id')) {
            id = searchObj.get('id')
            console.log('???',id);
        }
    }
    useEffect(()=>{
        if(!id){
            navigate('/')
        }
    },[])
    
    // console.log(id)
    // console.log(window.location.search)
    // let paramsObj = new URLSearchParams(useLocation().search)
    // console.log(paramsObj.get('id'))
    // let idTag=null
    // let paramsObj=new URLSearchParams(useLocation().search)
    // // path的动态参数部分
    // const {id}=useParams()
    // console.log('----',id)
    // // console.log(id);
    // // console.log(window.location.search)
    // // console.log(useLocation());
    // // html5
    
    // // console.log(paramsObj);
    // // console.log(paramsObj.get('id'))
    // let id2=paramsObj.get('id')
    // console.log('====',id2)
    // idTag=id || id2
    // console.log(idTag)
    return(
        <>
            Detail {id}
        </>
    )
}

export default Detail